<template>
  <div id="app">
    <button @click="add">add</button>
    <button @click="update">update</button>
    <button @click="lock">lock</button>
    <button @click="unlock">unlock</button>

    <ul>
      <li v-for="issue in issues" :key="issue.id">
        <a href="javascript:;">{{ issue.title }}</a>
      </li>
    </ul>
  </div>
</template>

<script>
import axios from 'axios';
export default {
  name: 'App',
  data() {
    return {
      issues: [],
    };
  },
  methods: {
    async add() {
      //为一个指定的仓库去新增一个issue
      //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
      //headers: {'Authorization': 'token 492e38d08089565967799b0e410963a4357c0814'}
      await axios({
        baseURL: 'https://api.github.com',
        url: '/repos/betterDamu/sh_200318/issues',
        method: 'post',
        data: {
          title: '东三省限电',
          body: '因为迪迦走了 带走了光',
        },
        headers: {
          Authorization: 'token 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',
        },
      });
    },

    async update() {
      //修改指定仓库的issue
      await axios({
        baseURL: 'https://api.github.com',
        url: '/repos/betterDamu/sh_200318/issues/369',
        method: 'patch',
        data: {
          title: '东三省限电啊啊啊啊啊!!!!',
        },
        headers: {
          Authorization: 'token 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',
        },
      });
    },

    async lock() {
      await axios({
        baseURL: 'https://api.github.com',
        url: '/repos/betterDamu/sh_200318/issues/369/lock',
        method: 'put',
        data: {
          lock_reason: 'too heated',
        },
        headers: {
          Authorization: 'token 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',
        },
      });
    },

    async unlock() {
      await axios({
        baseURL: 'https://api.github.com',
        url: '/repos/betterDamu/sh_200318/issues/369/lock',
        method: 'delete',
        headers: {
          Authorization: 'token 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',
        },
      });
    },
  },
  async mounted() {
    //get请求:  查询一个指定用户的指定仓库的所有issues
    const { data } = await axios({
      baseURL: 'https://api.github.com',
      url: '/repos/betterDamu/sh_200318/issues',
      method: 'get',
    });

    this.issues = data;
  },
};
</script>

<style scoped></style>
